package com.briup.bms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.briup.bms.common.utils.Result;
import com.briup.bms.service.ITitleService;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(tags = "职位信息服务")
@RestController
@RequestMapping("/title")
//@CrossOrigin(origins = "*")
public class TitleController {
	@Autowired
	private ITitleService titleService;

	@ApiOperation(value = "保存职称信息")
	@ApiImplicitParam(name = "title",value = "职称名字",required = true)
	@PostMapping
	public Result<String> addTitle(String title){
		titleService.saveTitle(title);
		return Result.success("保存成功！");
	}
	
	//@CrossOrigin(origins = "*")
	@ApiOperation(value = "按条件分页查找职称信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "pageNum",value = "页码",defaultValue = "1"),
		@ApiImplicitParam(name = "pageSize",value = "页面大小",defaultValue = "5"),
		@ApiImplicitParam(name = "title",value = "职称名字")
	})
	@GetMapping("/by/condition")
	public Result<PageInfo<Map<String, String>>> findByCondition(
			@RequestParam(defaultValue = "1")int pageNum,
			@RequestParam(defaultValue = "5")int pageSize,
			String title){
		 PageInfo<Map<String, String>> pageInfo = titleService.findByCondition(pageNum,pageSize,title);
		return Result.success(pageInfo);
	}
	
	//@CrossOrigin(origins = "*")
	@DeleteMapping("/{title}")
	public Result<String> deleteTitle(@PathVariable String title){
		titleService.deleteTitle(title);
		return Result.success("删除职称【"+title+"】成功！");
	}
	
}
